package com.huanglj.taobaounion.presenter.implement;

import com.huanglj.taobaounion.model.api.Api;
import com.huanglj.taobaounion.model.domain.SearchResult;
import com.huanglj.taobaounion.presenter.ISearchPresenter;
import com.huanglj.taobaounion.presenter.ISelectedPagePresenter;
import com.huanglj.taobaounion.utils.LogUtil;
import com.huanglj.taobaounion.utils.RetrofitManager;
import com.huanglj.taobaounion.view.ISearchCallBack;

import java.net.HttpURLConnection;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SearchPresenterImpl implements ISearchPresenter {
    private static final String TAG = "SearchPresenterImpl";
    @Override
    public void getLoadResult(String text) {
        Api api = RetrofitManager.getInstance().getRetrofit().create(Api.class);
        Call<SearchResult> call = api.getSearchResult("1", text);
        call.enqueue(new Callback<SearchResult>() {
            @Override
            public void onResponse(Call<SearchResult> call, Response<SearchResult> response) {
                if (response.code()== HttpURLConnection.HTTP_OK) {
                    String title = response.body().getData().getTbk_dg_material_optional_response().getResult_list().getMap_data().get(0).getTitle();
                    LogUtil.d(TAG,title);
                }
            }

            @Override
            public void onFailure(Call<SearchResult> call, Throwable t) {

            }
        });

    }

    @Override
    public void reLoad() {

    }

    @Override
    public void loadMore() {

    }

    @Override
    public void registerViewCallBack(ISearchCallBack callBack) {

    }

    @Override
    public void unregisterViewCallBack(ISearchCallBack callBack) {

    }
}
